package controller;

import gui.OptionPane;

import java.rmi.RemoteException;
import java.util.ArrayList;

import model.MessageInterface;
import toolkit.Debug;

public class Inbox extends Controller
{
	public Inbox()
	{
		setView(new view.Inbox(this));
	}
	
	public ArrayList<MessageInterface> getMessages()
	{
		try
		{
			return messageRemote.getMessages(user);
		}
		catch (RemoteException e)
		{
			Debug.log(e);
		}
		
		return null;
	}
	
	public void create()
	{
		forward(new controller.NewMessage());
	}
	
	public void delete(MessageInterface message)
	{
		if (OptionPane.showConfirm("Are you sure you wish to delete this message?") == 0)
		{
			try
			{
				messageRemote.deleteMessage(message);
			}
			catch (RemoteException e)
			{
				OptionPane.showError("Error", "Something went wrong when trying to delete the message.");
			}
		}
	}
	
	public void back()
	{
		forward(new controller.Lobby());
	}
}
